require("../model/studentsModel");
const mongoose = require("mongoose");
const { modelName } = require("../model/studentsModel");

/* GET home page. */
// router.get('/', function(req, res, next) {
//   res.render('index', { title: 'Express' });
// });

// 修改信息
async function changeStudent(req, res) {
    console.log("收到获取用户信息请求");
  
    //解密 会把token生成时传入的用户信息解密出来
    const token = req.get("Authorization").split(" ")[1];
    console.log("token为");
    console.log(token);
    let { studentId } = jwt.verify(token, "user");
    //更新用户

    let {modifiedCount} = await mongoose.model(modelName).updateOne({ _id: studentId }, req.body);
    if(modifiedCount>0){
      console.log("修改成功");
    }else{
      console.log("修改失败");
    }
    let result = await mongoose.model(modelName).find({ _id: studentId });
    res.send({ error_code: 0, data: result[0] });
  }
module.exports={changeStudent};

